package com.ta.gulimall.order.controller.web;

import com.ta.gulimall.common.utils.system.R;
import com.ta.gulimall.order.controller.OrderController;
import com.ta.gulimall.order.view.vo.OrderSubmitVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpRequest;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import java.util.concurrent.ExecutionException;

@Controller
public class OrderWebController {
    @Autowired
    OrderController orderController;

    @GetMapping("/confirm.html")
    public String confirm(Model model, HttpServletRequest request) throws ExecutionException, InterruptedException {
        R r = orderController.goodsConfirm(request);
        model.addAttribute("orderConfirmData", r.getData());
        return "confirm.html";
    }

    @PostMapping ("/submitOrder")
    public String submitOrder(Model model,OrderSubmitVo submitVo) {
        R r = orderController.submitOrder(submitVo);
        model.addAttribute("submitOrderResp", r.getData());
        return "pay.html";
    }
}
